home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / programs / internet / tcp / amitcp / amitcp-src-22.lha / AmiTCP-2.2 / src / appl / napsaterm / iconify.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-07  |  4.4 KB  |  161 lines

  1. RCS_ID_C "$Id: iconify.c,v 1.3 1991/11/14 07:20:38 ptp Exp $";
  2. /* This code has been highly modified for use in niftyterm.  Thanks
  3.  * to Leo Schwab for the nice example code.
  4.  * -- Todd Williamson, 12-14-89
  5.  *
  6.  * $Author: ptp $ $Revision: 1.3 $ $Date: 1991/11/14 07:20:38 $
  7.  */
  8.  
  9. #include "amiga.h"
  10.  
  11. /*  
  12.  *
  13.  * iconify.c:    You asked for it, you got it.
  14.  *
  15.  * Copyright 1987 by Leo L. Schwab.
  16.  * Permission is hereby granted for use in any and all programs, both
  17.  * Public Domain and commercial in nature, provided this Copyright notice
  18.  * is left intact.  Purveyors of programs, at their option, may wish observe
  19.  * the following conditions (in the spirit of hackerdom):
  20.  *    1: You send me a free, registered copy of the program that uses the
  21.  *       iconify feature,
  22.  *    2: If you're feeling really nice, a mention in the program's
  23.  *       documentation of my name would be neat.
  24.  *
  25.  *                     8712.10        (415) 456-3960
  26.  */
  27.  
  28. UWORD icon_data[6 * 18 * 2] = {
  29. 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  30. 0x3fff,0xffff,0xffff,0xffff,0xffff,0xffc0,
  31. 0x3fff,0xffff,0xffff,0xffff,0xffff,0xffc0,
  32. 0x3800,0x0000,0x0000,0x0000,0x0000,0x01c0,
  33. 0x3800,0x0000,0x0000,0x0000,0x0000,0x01c0,
  34. 0x3831,0x8607,0x0200,0x0200,0x0000,0x01c0,
  35. 0x3839,0x800d,0x8600,0x0600,0x0000,0x01c0,
  36. 0x383d,0x8e0c,0x0f99,0x8f8f,0x3b19,0x81c0,
  37. 0x3837,0x861e,0x0619,0x8619,0x9d9d,0xc1c0,
  38. 0x3833,0x860c,0x0619,0x861f,0x999a,0xc1c0,
  39. 0x3831,0x860c,0x068f,0x0698,0x1818,0xc1c0,
  40. 0x3831,0x8f1e,0x0306,0x030f,0x3c18,0xc1c0,
  41. 0x3800,0x0000,0x001c,0x0000,0x0000,0x01c0,
  42. 0x3800,0x0000,0x0000,0x0000,0x0000,0x01c0,
  43. 0x3800,0x0000,0x0000,0x0000,0x0000,0x01c0,
  44. 0x3fff,0xffff,0xffff,0xffff,0xffff,0xffc0,
  45. 0x3fff,0xffff,0xffff,0xffff,0xffff,0xffc0,
  46. 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  47. 0xffff,0xffff,0xffff,0xffff,0xffff,0xfff0,
  48. 0xffff,0xffff,0xffff,0xffff,0xffff,0xfff0,
  49. 0xf000,0x0000,0x0000,0x0000,0x0000,0x00f0,
  50. 0xf000,0x0000,0x0000,0x0000,0x0000,0x00f0,
  51. 0xf000,0x0000,0x0000,0x0000,0x0000,0x00f0,
  52. 0xf000,0x0000,0x0000,0x0000,0x0000,0x00f0,
  53. 0xf000,0x0000,0x0000,0x0000,0x0000,0x00f0,
  54. 0xf000,0x0000,0x0000,0x0000,0x0000,0x00f0,
  55. 0xf000,0x0000,0x0000,0x0000,0x0000,0x00f0,
  56. 0xf000,0x0000,0x0000,0x0000,0x0000,0x00f0,
  57. 0xf000,0x0000,0x0000,0x0000,0x0000,0x00f0,
  58. 0xf000,0x0000,0x0000,0x0000,0x0000,0x00f0,
  59. 0xf000,0x0000,0x0000,0x0000,0x0000,0x00f0,
  60. 0xf000,0x0000,0x0000,0x0000,0x0000,0x00f0,
  61. 0xf000,0x0000,0x0000,0x0000,0x0000,0x00f0,
  62. 0xf000,0x0000,0x0000,0x0000,0x0000,0x00f0,
  63. 0xffff,0xffff,0xffff,0xffff,0xffff,0xfff0,
  64. 0xffff,0xffff,0xffff,0xffff,0xffff,0xfff0,
  65. };
  66.  
  67. struct Image icon = {
  68.    0, 0, 92, 18, 2, &icon_data[0], 3, 0, NULL
  69. };
  70.  
  71. UWORD *chipbitmap=NULL;
  72. struct Image *chipimg=NULL;
  73.  
  74. /*
  75.  * Jim Mackraz suggested making icons easily identifiable by outside
  76.  * programs, so this constant gets stuffed into the UserData field.
  77.  */
  78. #define    ICON    0x49434f4eL        /*  'ICON'  */
  79.  
  80. static struct Gadget gadget = {
  81.     NULL,
  82.     0, 0, 0, 0,
  83.     NULL,                /*  Set later  */
  84.     GADGIMMEDIATE,
  85.     WDRAGGING,            /*  Observe the Magic!  */
  86.     NULL,                /*  Set later  */
  87.     NULL, NULL, NULL, NULL,
  88.     0, 0
  89. };
  90.  
  91. static struct NewWindow windef = {
  92.     0, 0, 0, 0,            /*  Set later  */
  93.     -1, -1,
  94.     GADGETDOWN,
  95.     SMART_REFRESH | NOCAREREFRESH,
  96.     &gadget,
  97.     NULL, NULL, NULL, NULL,        /*  Lotsa these  */
  98.     0, 0, 0, 0,
  99.     WBENCHSCREEN
  100. };
  101.  
  102. extern struct Window *w;
  103. static UWORD left=0, top=0;
  104.  
  105. iconify()
  106. {
  107.     UWORD width=icon.Width, height=icon.Height;
  108.  
  109.     windef.LeftEdge = left;
  110.     windef.TopEdge = top;
  111.     windef.Width = width;
  112.     windef.Height = height;
  113.  
  114.     gadget.Flags = GADGHCOMP | GRELWIDTH | GRELHEIGHT | GADGIMAGE;
  115.  
  116.     if (!openstuff())
  117.     return (0);
  118.  
  119.     return (1);
  120. }
  121.  
  122. deiconify()
  123. {
  124.     left = w->LeftEdge;
  125.     top = w->TopEdge;
  126.     closestuff();
  127. }
  128.     
  129. static openstuff()
  130. {
  131.     if(!(chipbitmap = (UWORD *)AllocMem((ULONG)sizeof(icon_data), MEMF_CHIP | MEMF_PUBLIC))) {
  132.     puts("Can't allocate image bitmap");
  133.     return FALSE;
  134.     }
  135.     CopyMem((char *)icon_data, (char *)chipbitmap, (int) sizeof(icon_data));
  136.  
  137.     /* copy the image structure too */
  138.     if(!(chipimg = (struct Image *)AllocMem((ULONG)sizeof(icon), MEMF_CHIP | MEMF_PUBLIC))) {
  139.     FreeMem(chipbitmap, (ULONG)sizeof(icon_data));
  140.     puts("Can't allocate image structure");
  141.     return FALSE;
  142.     }
  143.     CopyMem((char *)&icon, (char *)chipimg, (int) sizeof(icon));
  144.     chipimg->ImageData = chipbitmap;
  145.     gadget.GadgetRender = (APTR)chipimg;
  146.     if (!(w = OpenWindow(&windef)))
  147.         return (0);
  148.     w->UserData = (BYTE *)ICON;
  149.     return (1);
  150. }
  151.  
  152. static closestuff ()
  153. {
  154.     FreeMem(chipimg, (ULONG)sizeof(icon));
  155.     FreeMem(chipbitmap, (ULONG)sizeof(icon_data));
  156.     if(w)
  157.         CloseWindow(w);
  158. }
  159.  
  160.  
  161.